// 本文件对Encoder的方法进行性能测试
// @Author: zhengqi Wu
// @Description:
// @Version: 1.0.0
// @Date: 2021/4/8 9:11 下午
// @Copyright: MIN-Group；国家重大科技基础设施——未来网络北大实验室；深圳市信息论与未来网络重点实验室
//
const benchmark = require('benchmark')
const {Encoder, MaxPacketSize} = require('./Encoder')

let enc1 = new Encoder()
const suite1 = new benchmark.Suite()
suite1.add('测试Encoder初始化性能', () => {
    enc1.encoderReset(MaxPacketSize, 0)
}).on('cycle', (event) => {
    console.log(String(event.target))
}).on('complete', () =>{
    console.log('Encoder初始化 finished')
}).run()

const suite2 = new benchmark.Suite()
suite2.add('测试Encoder前插一个字节性能', () => {
    let enc2 = new Encoder()
    enc2.encoderReset(MaxPacketSize, 0)
    enc2.prependByte(97)
}).on('cycle', (event) => {
    console.log(String(event.target))
}).on('complete', () =>{
    console.log('Encoder前插一个字节 finished')
}).run()

const suite3 = new benchmark.Suite()
suite3.add('测试Encoder前插一个字节数组性能', () => {
    let enc = new Encoder()
    enc.encoderReset(MaxPacketSize, 0)
    let buffer = new Uint8Array([1, 2, 3, 4, 5])
    let length = buffer.length
    enc.prependByteArray(buffer.buffer, BigInt(length))
}).on('cycle', (event) => {
    console.log(String(event.target))
}).on('complete', () =>{
    console.log('Encoder前插一个字节数组 finished')
}).run()

const suite4 = new benchmark.Suite()
suite4.add('Encoder前插变长整型性能', () => {
    let enc = new Encoder()
    enc.encoderReset(MaxPacketSize, 0)
    enc.prependVarNumber(240)
}).add('Encoder前插变长整型性能', () => {
    let enc = new Encoder()
    enc.encoderReset(MaxPacketSize, 0)
    enc.prependVarNumber(65535)
}).add('Encoder前插变长整型性能', () => {
    let enc = new Encoder()
    enc.encoderReset(MaxPacketSize, 0)
    enc.prependVarNumber(65536)
}).add('Encoder前插变长整型性能', () => {
    let enc = new Encoder()
    enc.encoderReset(MaxPacketSize, 0)
    enc.prependVarNumber(4294967296n)
}).add('Encoder前插变长整型性能', () => {
    let enc = new Encoder()
    enc.encoderReset(MaxPacketSize, 0)
    enc.prependVarNumber(18446744073709551615n)
}).on('cycle', (event) => {
    console.log(String(event.target))
}).on('complete', () =>{
    console.log('Encoder前插一个字节数组 finished')
}).run()
